home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v9n03.arc / MIRDIR.ASM < prev    next >
Assembly Source File  |  1990-01-12  |  16KB  |  260 lines

  1.          PAGE  60,132
  2.          TITLE MIRDIR - Directory Mirror program
  3. ;        SUBTTL  General program description and use of common storage
  4. ; ----------------------------------------------------------------------------;
  5. ;        MIRDIR - Enter identical directory on another drive as current direct;
  6. ; ----------------------------------------------------------------------------;
  7. ;   MIRDIR 1.0 ■ PCDATA TOOLKIT Copyright (c) 1990 Ziff Communications Co.    ;
  8. ;                   PC Magazine ■ Wolfgang Stiller                            ;
  9. ;                                                                             ;
  10. ;-----------------------------------------------------------------------------;
  11.  
  12. ; Purpose:                                                                    ;
  13. ;  To "mirror" the directory structure from one disk to another disk.         ;
  14. ;  MIRDIR will determine the current directory name, and attempt to           ;
  15. ;  change to, or create the same directory on the specified disk.             ;
  16. ; ----------------------------------------------------------------------------;
  17. ;Format:                                                                      ;
  18. ;                                                                             ;
  19. ;MIRDIR d:                                                                    ;
  20. ;                                                                             ;
  21. ;   d: Specifies the drive on which the current directory is to be mirrored.  ;
  22. ;                                                                             ;
  23. ; ----------------------------------------------------------------------------;
  24. ;Remarks:                                                                     ;
  25. ;                                                                             ;
  26. ;    "Mirroring" means to change to the same directory on another drive       ;
  27. ;    as the current directory on the default drive. If this directory         ;
  28. ;    does not exist, then MIRDIR will attempt to create the directory.        ;
  29. ;    MIRDIR will only create a new directory if the parent for the            ;
  30. ;    missing directory exists. In other words if the current directory        ;
  31. ;    name is: "A\B\C", MIRDIR will fail if the target disk does not have      ;
  32. ;    a directory named "A\B" or one named "A\B\C".  If MIRDIR is used         ;
  33. ;    with program Xall, this condition will automatically be satisfied,       ;
  34. ;    if executed from the root directory.                                     ;
  35. ;                                                                             ;
  36. ; MIRDIR will return the following DOS error levels:                          ;
  37. ;   128 (40h) if fatal error on starting such as bad syntax.                  ;
  38. ;    32 (20h) indicates MIRDIR unable to mirror the directory. This means it  ;
  39. ;             attempted to create the directory and failed.                   ;
  40. ;    04       Directory was not found on target volume, but MIRDIR created it.;
  41. ;    00       Normal completion.                                              ;
  42. ;                                                                             ;
  43. ; ----------------------------------------------------------------------------;
  44.  
  45. ;---------------------------------------------------------------;
  46. ; Constants:                                                    ;
  47. ;---------------------------------------------------------------;
  48. BOX     EQU    254                        ;Small box character code
  49. CR      EQU    0Dh
  50. LF      EQU    0Ah
  51. CRLF    EQU    0A0Dh                      ;Carriage return line feed.
  52.  
  53. CSEG    SEGMENT
  54.         ASSUME  CS:CSEG, DS:CSEG, ES:CSEG, SS:CSEG
  55.  
  56.         SUBTTL  Main program
  57. ;******************************************************************************;
  58. ;**   Main program begins here -MIRDIR-                                      **;
  59. ;******************************************************************************;
  60.         ORG     100H                      ; This is a .COM type program
  61. MIRDIR:
  62.         CALL    Parse_parms_Print_Header  ;Parse cmdline paramters + prnt header
  63.                                           ;Set mirror drive letter in path strng
  64.         XOR     BP,BP                     ;Set zero as highest return code
  65.         CALL    Get_Current_Directory     ;Get name of current directory
  66.         CALL    Mirror_Current_Directory  ;Now change other drive to same dir
  67.         MOV     AX,BP                     ;BP contains highest return code
  68.         MOV     AH,4Ch                    ;   terminate with  return code
  69.         INT     21h
  70.  
  71. ;---------------------------------------------------------------------------;
  72. ; GET CURRENT DIRECTORY                                                     ;
  73. ;   Ask DOS for current directory string. Store it in a substring of        ;
  74. ;   Mir_Directory.                                                          ;
  75. ;---------------------------------------------------------------------------;
  76. Get_Current_Directory:                    ;Determine current directory
  77.         MOV     SI,offset Current_Path    ;Place to store original directory
  78.         XOR     DL,DL                     ;Zero DL in order to use default drive
  79.         MOV     AH,47h                    ;Get current directory (path) func
  80.         INT     21h
  81.         RET
  82.  
  83.  
  84. ;---------------------------------------------------------------------------;
  85. ; MIRROR CURRENT DIRECTORY                                                  ;
  86. ;   Try to change to the directory on users specified "Mirror_drive" to     ;
  87. ;   match the current directory which we stored in substring of             ;
  88. ;   Mir_Directory. If this fails, we will attempt to create this            ;
  89. ;   directory and then change to that directory.                            ;
  90. ;---------------------------------------------------------------------------;
  91. Mirror_Current_Directory:
  92. ; 1) Attempt change to same directory as on current drive
  93.         MOV     DX, offset Mir_Directory  ;Directory name including drive.
  94.         MOV     AH,3Bh                    ;Set current directory function
  95.         INT     21h
  96.         JC      Invalid_path              ;IF function failed
  97.         RET                               ;It worked! we are all done.
  98. Invalid_Path:                             ;Change dir failed so try MKdir
  99. ; 2) If change failed then try to create the missing directory
  100.         MOV     AH,39h                    ;DOS create directory function
  101.                                           ;DX already points to directory string
  102.         INT     21h                       ;Create new directory
  103.         JC      Create_Dir_Failed         ;If creation of new directory failed..
  104. ; 3) Now change over to the newly created directory
  105.         MOV     AH,3Bh                    ;Set current directory function
  106.         INT     21h                       ;Set to the newly created directory
  107.         JC      Create_Dir_Failed         ;IF failure (should never happen)
  108.                                           ;It worked! Tell user we created dirct
  109.         MOV     BP,04h                    ;Set error level for "create worked"
  110.         MOV     DX, offset Dir_create_Msg ;beginning of "Create" message
  111.         MOV     CX,13                     ;Number of chars in message
  112.         CALL    Display_Directory_Name    ;Display message + directory name
  113.         RET
  114. Create_Dir_Failed:
  115.         MOV     DX, offset Bad_create_Msg ;beginning of "Create failed" message
  116.         MOV     CX,19                     ;Number of chars in message
  117.         CALL    Display_Directory_Name    ;Display message + directory name
  118.  
  119.         MOV     DX,OFFSET Create_detail_Msg  ;Give user details of failure
  120.         MOV     AH,09h                    ;DOS display string function
  121.         INT     21H
  122.  
  123. ; Produce a beep to alert the user:  (use  BIOS TTY func to write an ASCII BELL)
  124.         MOV     AX,0E07H                  ;BIOS func (0Eh) to write (07H) beep
  125.         XOR     BH,BH                     ;Select page zero for output
  126.         INT     10H                       ;BIOS video function (0Eh=write char)
  127.  
  128. ; Wait for user to hit any key
  129.         XOR     AX,AX
  130.         INT     16h                       ;Wait for user to hit a key
  131.  
  132.         MOV     BP,20h                    ;Error level code for batch file use
  133.         RET
  134.  
  135. ;---------------------------------------------------------------------------;
  136. ; DISPLAY DIRECTORY NAME                                                    ;
  137. ;   Display message pointed to by DX of length CX and the directory and     ;
  138. ;   drive string in Mir_Directory.                                          ;
  139. ;---------------------------------------------------------------------------;
  140. Display_Directory_Name:
  141.         MOV     AH,40h                    ;DOS Write func
  142.         MOV     BX,1                      ;Handle for std output device
  143.         INT     21h                       ;Write Start of message
  144. ;   Scan the string in Mir_Directory to determine its length:
  145.         CLD                               ;Forward Scan
  146.         MOV     DI,OFFSET Mir_Directory   ;Location of Mir_Directory
  147.         MOV     DX,DI                     ;Saved copy of directory start
  148.         XOR     AX,AX                     ;Scan for zero termination of string
  149.         MOV     CX,67                     ;Scan up to 67 characters
  150.         REPNE   SCASB                     ;Find 1st zero byte
  151.         SUB     DI,DX                     ;Length of directory string
  152.         MOV     CX,DI                     ;Characters to display in dir string
  153. ;DX = start of dir strng, CX = # of chars in string
  154.         MOV     AH,40h                    ;DOS Write func
  155.         INT     21h                       ;Display the actual directory string
  156.         MOV     DX,OFFSET CRLF_str        ;Prepare to put out carriage ret + LF
  157.         MOV     CX,2                      ;Print 2 characters
  158.         MOV     AH,40h                    ;DOS Write func
  159.         INT     21h
  160.         RET
  161.  
  162.         SUBTTL  Initialization code
  163.         PAGE
  164. ; ----------------------------------------------------------------------------;
  165. ; Initialization code - parse parms + place drive letter in path string       ;
  166. ; ----------------------------------------------------------------------------;
  167. Parse_parms_Print_Header:                 ;Parse input parameters + print header
  168.         MOV     SI,80H                    ;Parameter area in PSP
  169.         MOV     CL,[SI]                   ;Get # of chars in input parm
  170.         XOR     CH,CH                     ;Clear upper byte of char count
  171.         OR      CL,CL                     ;Check for 0 chars (NO INPUT)
  172.         MOV     DX, OFFSET Missing_D_Msg  ;Prepare syntax description message
  173.         JZ      ERR_EXIT                  ;IF NO PARMS, give user correct syntax
  174.         INC     SI                        ;Point to 1st char
  175.         CLD                               ;Forward direction
  176.  
  177. DEL_SPACES:
  178.         LODSB                             ;Get byte at DS:SI and inc SI
  179.         CMP     AL,' '                    ;Is it a space?
  180.         JNE     Check_for_drive           ;If not we have something..
  181.         LOOP    DEL_SPACES                ;CONT CHECKING UNTIL LAST CHAR
  182. ERR_EXIT:
  183.         MOV     AH,09h                    ;DOS display string function
  184.         INT     21H
  185.  
  186. ; Produce a beep to alert the user:  (use  BIOS TTY func to write an ASCII BELL)
  187.         MOV     AX,0E07H                  ;BIOS func (0Eh) to write (07H) beep
  188.         XOR     BH,BH                     ;Select page zero for output
  189.         INT     10H                       ;BIOS video function (0Eh=write char)
  190.  
  191. ; Wait for user to hit any key
  192.         XOR     AX,AX
  193.         INT     16h                       ;Wait for user to hit a key
  194.  
  195.         MOV     DX, OFFSET Syntax_msg     ;Prepare syntax description message
  196.         MOV     AH,09h                    ;DOS display string function
  197.         INT     21H
  198.         MOV     AX,4C80h                  ;   terminate with 40h return code
  199.         INT     21h
  200. ;---------------------------------------------------------------------------;
  201. ; Conventions for command line parsing:                                     ;
  202. ;   SI points to next char to be checked in the parm field at DS:80         ;
  203. ;   CX is count of characters left to be scanned                            ;
  204. ;---------------------------------------------------------------------------;
  205. Check_for_drive:
  206.         CMP     BYTE PTR [SI],':'         ;Check for presence of drive spec
  207.         JNZ     ERR_Exit                  ;Give user some help...
  208.         AND     AL,5Fh                    ;Capitalize drive letter
  209.         MOV     Mir_Drive,AL              ;Save a copy of drive letter
  210.         MOV     DX,OFFSET Start_Msg       ;Initial message
  211.         MOV     AH,09H                    ;DOS display string function
  212.         INT     21H
  213.         RET
  214.  
  215.         SUBTTL  Definition of Data structures
  216.         PAGE
  217. ;******************************************************************************;
  218. ;**   Definition of Data areas follow                                        **;
  219. ;******************************************************************************;
  220. Root_dir      DB  '\',0                   ;Zero terminated root dir string
  221. Mir_directory Label BYTE                  ;Same as location "Mir_Drive"
  222. Mir_Drive     DB   'A:'                   ;Name of drive to be mirrored
  223.               DB   '\'                    ;Force 1st char directry strng to '\'
  224. Current_Path  DB   64 DUP (0)             ;Save area to restore original path
  225.  
  226. Start_MSG     DB  CR,LF,"MIRDIR 1.0 ",BOX," PCDATA TOOLKIT (c) 1990"
  227.               DB  " Ziff Communications Co.",CR,LF
  228.               DB  "PC Magazine ",BOX," Wolfgang Stiller",CR,LF,"$"
  229. Missing_D_Msg DB  'The drive letter of the target drive is missing.',CR,LF
  230.               DB  'It should be entered with a colon.',CR,LF
  231.               DB  'Example:',CR,LF
  232.               DB  '          MIRDIR A:',CR,LF
  233.               DB  'will mirror the current directory on drive A.',CR,LF,Lf
  234.               DB  'Please hit a key - ',CR,LF,LF,'$'
  235. Syntax_Msg    DB  "MIRDIR 1.0 ",BOX," PCDATA TOOLKIT Copyright (c) 1990"
  236.               DB  " Ziff Communications Co.",CR,LF
  237.               DB  "PC Magazine ",BOX," Wolfgang Stiller",CR,LF,CR,LF
  238.               DB  'Syntax is: MIRDIR d:',CR,LF,LF
  239.               DB  'd:  is the drive upon which MIRDIR will "mirror" '
  240.               DB  'the current directory.',CR,LF
  241.               DB  '    MIRDIR will change to a directory on drive d: '
  242.               DB  'which matches the',CR,LF
  243.               DB  '    current directory. If not found, it will try to '
  244.               DB  'create the directory.'
  245. CRLF_str      DB   CR,LF,'$'
  246. Bad_Create_Msg    DB 'Create failed for: '
  247. Dir_Create_Msg    DB 'Created dir: '
  248. Create_Detail_Msg DB CR,LF,'The create probably failed due to 1 of 2 reasons:'
  249.                   DB CR,LF
  250.                   DB ' 1) There is a insufficient space on the target disk'
  251.                   DB CR,LF,'     or',CR,LF
  252.                   DB ' 2) The parent directory did not exist. For example,'
  253.                   DB CR,LF
  254.                   DB '    to create directory "\A\B", directory "\A" must '
  255.                   DB ' first exist.'
  256.                   DB CR,LF,LF,'Please hit a key',CR,LF,'$'
  257. User_file_spec EQU  $                ;User specified file spec to check
  258. CSEG    EndS
  259.         END     MIRDIR
  260.